<template>
	<view>
		<view>
			<navi-shell :back="false" title="LZZY习题通">
			</navi-shell>
		</view>

		<view>
			<view v-if="isLogin">
				<view class="head-container">
					<image :src="avatar" mode="aspectFill" class="img-avatar">
					</image>
					<view class="user-info-container">
						<view class="nick-type-container">
							<text class="nick-badge">{{nick+"["+userTypes[type]+"]"}}</text>
						</view>
					</view>
				</view>
				<text class="iconfont icon-guanbi icon-guanbi" @click="clickLogout"></text>
			</view>
			<login-dialog ref="login" @after="afterLogin"></login-dialog>
		</view>

		<view v-if="type==0" class="fenlei">
			<view class="genren">
				<text class="iconfont icon-yonghu-yuan ic-geren"></text>
				<text class="wenzi">个人中心</text>
			</view>
			<view class="genren" @tap="tapUser()">
				<text class="iconfont icon-feiji ic-geren"></text>
				<text class="wenzi">用户管理</text>
			</view>
			<view class="genren" @tap="tapquanxian()">
				<text class="iconfont icon-mima ic-geren"></text>
				<text class="wenzi">权限模块管理</text>
			</view>
		</view>

		<view v-if="type==1" class="fenlei">
			<view class="two">
				<text class="iconfont icon-yonghu-yuan ic-geren"></text>
				<text class="wenzi">个人中心</text>
			</view>
			<view class="two" @tap="tapKecheng()">
				<text class="iconfont icon-24 ic-geren"></text>
				<text class="wenzi">课程管理</text>
			</view>
			<view class="two">
				<text class="iconfont icon-feiji ic-geren"></text>
				<text class="wenzi">学生管理</text>
			</view>
			<view class="two" @tap="taptianjia()">
				<text class="iconfont icon-tianjia ic-geren"></text>
				<text class="wenzi">添加课程</text>
			</view>
		</view>

		<view v-if="type==2" class="fenlei">
			<view class="genren">
				<text class="iconfont icon-yonghu-yuan ic-geren"></text>
				<text class="wenzi">个人中心</text>
			</view>
			<view class="genren" @tap="tpastuclass()">
				<text class="iconfont icon-24 ic-geren"></text>
				<text class="wenzi">课程列表</text>
			</view>
		</view>

	</view>
</template>

<script>
	const app = getApp()
	let newName = ""
	let updateId = ""
	let page = 0
	let ids = []
	export default {
		data() {
			return {
				isLogin: app.globalData.token.length > 0,
				avatar: this.$params.host + app.globalData.avatar,
				name: '',
				email: '',
				nick: '',
				type: 66,
				userTypes: ["管理员", "教师", "学生"],
			}
		},
		mounted() {
			if (!this.isLogin) {
				this.$refs.login.show()
			}
		},
		onShow() { //tab页切换时要
			if (!this.isLogin) {
				return
			}
			// this.loadData()
		},
		onLoad() {
			this.$noti.add(this.$params.noti_login_status, this, this.afterLogin)
		},
		onUnload() {
			this.$noti.remove(this.$params.noti_login_status, this)
		},
		methods: {
			//跳转用户管理
			tapUser() {
				uni.navigateTo({
					url: '../admin/admin',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			//跳转权限模块
			tapquanxian() {
				uni.navigateTo({
					url: '../guanlionghu/guanliyonghu',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			//跳转课程管理
			tapKecheng() {
				uni.navigateTo({
					url: '../teacherke/teacherke',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}, //课程添加
			taptianjia() {
				uni.navigateTo({
					url: '../add/add',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			//学生课程
			tpastuclass() {
				uni.navigateTo({
					url: '../stuclass/stuclass',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			// 登录之后
			afterLogin(logout) {
				if (logout) {
					this.$refs.login.show()
					return
				}
				this.isLogin = app.globalData.token.length > 0
				this.avatar = this.$params.host + app.globalData.avatar
				this.type = app.globalData.type
				this.name = app.globalData.userName
				this.email = app.globalData.email
				this.nick = app.globalData.nickName
			},
			clickLogout() {
				this.isLogin = false
				app.globalData.avatar = '../../static/icons/default_user.png'
				app.globalData.uid = ''
				app.globalData.type = -1
				app.globalData.email = ''
				app.globalData.nickName = ''
				app.globalData.userName = ''
				app.globalData.token = ''
				this.$noti.post(this.$params.noti_login_status, true)
			},

		}
	}
</script>

<style>
	@import url("index.css");
</style>
